var socket = io.connect('http://localhost:1337');

var debugMsg = '';

//Variables globales et constantes
var canvas = document.getElementById('screen');
    canvas.style.width = 800 + 'px';
    canvas.style.height = 600 + 'px';

var c = canvas.getContext('2d');

canvas.getWidth = function() {
    return (parseInt(this.style.width));
};

canvas.getHeight = function() {
    return (parseInt(this.style.height));
};

var canvasOffset = {
    left: 25,
    top: 25
}

//Représente la map client side
var tileMap = [];
//Représente le héros client side
var hero = {};
    hero.connected = false;
//TODO implement connected or not
//Représente les héros enemis
var enemyHeroes = [];

//Global vars send du srv
var grid = {
    width: -1,
    height: -1
};

var playerAreaBase = -1;
var playerRangeBase = -1;

var defaultTileWidth = -1;
var defaultTileHeight = -1;

//Global vars UI
var ui_top, ui_top_gold, ui_top_level;
var ui_bottom, ui_bottom_content;
var ui_gameMsg, ui_msg;

//is the user selecting a building to store harvest
var isSelectingBuilding = false;
//ui_right info panel vars
var selectedTile, selectedCrop, selectedBuilding;

var astar_path = 'js/client/Utils/astar.js';

var camera = {
    x: 0,
    y: 0
}

// --- ENUMS ---

var TIME_MS = {
    SECOND:         1000,
    MINUTE:         60000,
    HOUR:           3600000,
    DAY:            86400000
}

var BUILDINGS = {
    SILO:           1,
    BARN:           2,
    COLDSTORAGE:    3
}

var CROPS = {
    TOMATO:         10,
    CORN:           20,
    WHEAT:          30
}

var HEALTH = {
    GOOD:           100,
    MEDIUM:         200,
    AVERAGE:        300,
    LOW:            400,
    BAD:            500
}

var WEAPONS = {
    FORK:           1000,
    BASEBALL_BAT:   2000,
    CHAINSAW:       3000,
    AK47:           4000
}

function convertTypeToStr(type) {
    switch(type) {
        case CROPS.TOMATO:
            return 'Tomato';
            break;
        case CROPS.CORN:
            return 'Corn';
            break;
        case CROPS.WHEAT:
            return 'Wheat';
            break;

        case BUILDINGS.SILO:
            return 'Silo';
            break;
        case BUILDINGS.BARN:
            return 'Barn';
            break;
        case BUILDINGS.COLDSTORAGE:
            return 'Coldstorage';
            break;
    }
}

var keys = {
    UP: 38,
    DOWN: 40,
    LEFT: 37,
    RIGHT: 39,
    Z: 90,
    Q: 81,
    S: 83,
    D: 68,
    B: 66,
    N: 78
}

